package com.itmayiedu.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.itmayiedu.base.ResponseBase;
import com.itmayiedu.constants.Constants;
import com.itmayiedu.entity.UserEntity;
import com.itmayiedu.feign.MemberServiceFeign;

@Controller
public class RegisterController {
	@Autowired
	private MemberServiceFeign memberServiceFeign;
	private static final String REGISTER="register";
	private static final String LOGIN="login";
	@RequestMapping(value="/register",method=RequestMethod.GET)
	public String registerGet() {
		return REGISTER;
	}
	//注册业务具体
	@RequestMapping(value="/register",method=RequestMethod.POST)
	public String registerPost(UserEntity userEntity ,HttpServletRequest request) {
		//1.验证参数 	
		
		//2.调用会员注册接口
			ResponseBase regUser = memberServiceFeign.registerUser(userEntity);
		//3.如果失败跳转失败页面
			if(!regUser.getCode().equals(Constants.HTTP_RES_CODE_200)) {
				request.setAttribute("error", "注册失败");
			}
		return LOGIN;
	}
}
